package org.example.controller;

import java.util.List;
import org.example.dto.RestResult;
import org.example.entity.UserLogDO;
import org.example.query.UserLogQuery;
import org.example.service.UserLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.Min;

/**
 * 用户操作日志控制器
 */
@RestController
@RequestMapping("/user-log")
@Validated
public class UserLogController {
    @Autowired
    private UserLogService userLogService;

    @PostMapping("/register")
    public RestResult<Void> recordRegisterLog(@RequestParam @Min(1) Integer userId, @RequestParam String details) {
        return userLogService.recordRegisterLog(userId, details);
    }

    @PostMapping("/login")
    public RestResult<Void> recordLoginLog(@RequestParam @Min(1) Integer userId, 
                                           @RequestParam String ipAddress, 
                                           @RequestParam String userAgent, 
                                           @RequestParam String details) {
        return userLogService.recordLoginLog(userId, ipAddress, userAgent, details);
    }

    @PostMapping("/logout")
    public RestResult<Void> recordLogoutLog(@RequestParam @Min(1) Integer userId, @RequestParam String details) {
        return userLogService.recordLogoutLog(userId, details);
    }

    @GetMapping("/query")
    public RestResult<List<UserLogDO>> queryUserLogs(@ModelAttribute @Validated UserLogQuery query) {
        return userLogService.queryUserLogs(query);
    }
}